package com.iot.inclinometer.util;

import com.iot.inclinometer.pojo.BaseInfo;
import com.iot.inclinometer.pojo.CorrectDataInfo;
import com.iot.inclinometer.pojo.DataInfo;
import com.iot.inclinometer.pojo.LeijiInfo;
import com.iot.inclinometer.pojo.ObserveInfo;
import com.iot.inclinometer.pojo.RealInfo;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;


public class JXLImportAll {
	    //实时数据信息
		public static List<RealInfo> loadRealInfo(String xlsPath){
			List<RealInfo> list= new ArrayList<RealInfo>();
			try {
				Workbook book = Workbook.getWorkbook(new File(xlsPath));
				//获得第一个工作表对象
				Sheet sheet = book.getSheet(0);				
				RealInfo realInfo = null;
				
				//循环行Row，观测信息
			 	for (int rowNum = 1; rowNum <sheet.getRows(); rowNum++) {
			 		Cell[] cells = sheet.getRow(rowNum);
		            if (cells == null) {
		                continue;
		            }
		            realInfo = new RealInfo();
		            //循环列Cell
		            Cell real_id = cells[0];
		            if (real_id == null) {
		                continue;
		            }		                
		            realInfo.setRealId(Integer.parseInt(real_id.getContents()));
		           
		            Cell theta_A = cells[1];
		            if (theta_A == null) {
		                continue;
		            }		                
		            realInfo.setTheta_A(theta_A.getContents()); 
		            
		            Cell theta_B = cells[2];
		            if (theta_B == null) {
		                continue;
		            }		                
		            realInfo.setTheta_B(theta_B.getContents());
		            
		            Cell ltheta_A = cells[3];
		            if (ltheta_A == null) {
		                continue;
		            }		                
		            realInfo.setLtheta_A(ltheta_A.getContents());
		            
		            Cell ltheta_B = cells[4];
		            if (ltheta_B == null) {
		                continue;
		            }		                
		            realInfo.setLtheta_B(ltheta_B.getContents());
		            Cell lltheta_A = cells[5];
		            if (lltheta_A == null) {
		                continue;
		            }		                
		            realInfo.setLltheta_A(lltheta_A.getContents());
		            
		            Cell lltheta_B = cells[6];
		            if (lltheta_B == null) {
		                continue;
		            }		                
		            realInfo.setLltheta_B(lltheta_B.getContents());
		            
		            Cell currentMeasureTag = cells[7];
		            if (currentMeasureTag == null) {
		                continue;
		            }		                
		            realInfo.setCurrentMeasureTag(currentMeasureTag.getContents());
		            
		            Cell ob_id = cells[8];
		            if (ob_id == null) {
		                continue;
		            }		                
		            realInfo.setObserverId(Integer.parseInt(ob_id.getContents()));
		            list.add(realInfo);
			 	}			 	
			 	book.close();		 	
			} catch (BiffException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return list;
		}
    
		//累计数据信息
		public static List<LeijiInfo> loadLeijiInfo(String xlsPath){
				List<LeijiInfo> list= new ArrayList<LeijiInfo>();
				try {
					Workbook book = Workbook.getWorkbook(new File(xlsPath));
					//获得第一个工作表对象
					Sheet sheet = book.getSheet(1);				
					LeijiInfo ljdataInfo = null;
					//循环行Row，观测信息
				 	for (int rowNum = 1; rowNum <sheet.getRows(); rowNum++) {
				 		Cell[] cells = sheet.getRow(rowNum);
			            if (cells == null) {
			                continue;
			            }
			            ljdataInfo = new LeijiInfo();
			            //循环列Cell
			            Cell leiji_id = cells[0];
			            if (leiji_id == null) {
			                continue;
			            }		                
			            ljdataInfo.setLeijiId(Integer.parseInt(leiji_id.getContents()));
			            
			            Cell depth = cells[1];
			            if (depth == null) {
			                continue;
			            }		                
			            ljdataInfo.setDepth(depth.getContents());
			            
			            Cell lx = cells[2];
			            if (lx == null) {
			                continue;
			            }		                
			            ljdataInfo.setLx(lx.getContents());
			            
			            Cell ly = cells[3];
			            if (ly == null) {
			                continue;
			            }		                
			            ljdataInfo.setLy(ly.getContents());
			            
			            
			            Cell theta_x = cells[4];
			            if (theta_x == null) {
			                continue;
			            }		                
			            ljdataInfo.setThetaX(theta_x.getContents());
			            
			            Cell theta_y = cells[5];
			            if (theta_y == null) {
			                continue;
			            }		                
			            ljdataInfo.setThetaY(theta_y.getContents());
			          
			            Cell ob_id = cells[6];
			            if (ob_id == null) {
			                continue;
			            }		                
			            ljdataInfo.setObserverId(Integer.parseInt(ob_id.getContents()));

			            list.add(ljdataInfo);
				 	}
				 	
				 	book.close();
				 	
				} catch (BiffException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return list;
			}
	
		//修正数据信息
		public static List<CorrectDataInfo> loadCorrectDataInfo(String xlsPath){
			List<CorrectDataInfo> list= new ArrayList<CorrectDataInfo>();
			try {
				Workbook book = Workbook.getWorkbook(new File(xlsPath));
				//获得第一个工作表对象
				Sheet sheet = book.getSheet(2);
				CorrectDataInfo correctDataInfo = null;
				//循环行Row，观测信息
			 	for (int rowNum = 1; rowNum <sheet.getRows(); rowNum++) {
			 		Cell[] cells = sheet.getRow(rowNum);
		            if (cells == null) {
		                continue;
		            }
		            correctDataInfo = new CorrectDataInfo();
		            //循环列Cell
		            Cell data_id = cells[0];
		            if (data_id == null) {
		                continue;
		            }
		            correctDataInfo.setDataId(Integer.parseInt(data_id.getContents()));
		            
		            Cell depth = cells[1];
		            if (depth == null) {
		                continue;
		            }
		            correctDataInfo.setDepth(depth.getContents());
		            
		            Cell lx = cells[2];
		            if (lx == null) {
		                continue;
		            }
		            correctDataInfo.setLx(lx.getContents());
		            
		            Cell ly = cells[3];
		            if (ly == null) {
		                continue;
		            }		                
		            correctDataInfo.setLy(ly.getContents());
		            
		            Cell error = cells[4];
		            if (error == null) {
		                continue;
		            }		                
		            correctDataInfo.setError(error.getContents());
		            
		            Cell theta_x = cells[5];
		            if (theta_x == null) {
		                continue;
		            }		                
		            correctDataInfo.setThetaX(theta_x.getContents());
		            
		            Cell theta_y = cells[6];
		            if (theta_y == null) {
		                continue;
		            }		                
		            correctDataInfo.setThetaY(theta_y.getContents());
		            
		            Cell theta = cells[7];
		            if (theta == null) {
		                continue;
		            }		                
		            correctDataInfo.setTheta(theta.getContents());           
		            
		            Cell ob_id = cells[8];
		            if (ob_id == null) {
		                continue;
		            }		                
		            correctDataInfo.setObserverId(Integer.parseInt(ob_id.getContents()));
		            
		            Cell A0 = cells[9];
		            if (A0 == null) {
		                continue;
		            }		                
		            correctDataInfo.setA0(A0.getContents());
		            
		            Cell B0 = cells[10];
		            if (B0 == null) {
		                continue;
		            }		                
		            correctDataInfo.setB0(B0.getContents());
		            
		            Cell A180 = cells[11];
		            if (A180 == null) {
		                continue;
		            }		                
		            correctDataInfo.setA180(A180.getContents());
		            
		            Cell B180 = cells[12];
		            if (B180 == null) {
		                continue;
		            }		                
		            correctDataInfo.setB180(B180.getContents());
		            
		            list.add(correctDataInfo);
			 	}
			 	
			 	book.close();
			 	
			} catch (BiffException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return list;
		}	

		//数据信息
		public static List<DataInfo> loadDataInfo(String xlsPath){
			List<DataInfo> list= new ArrayList<DataInfo>();
			try {
				Workbook book = Workbook.getWorkbook(new File(xlsPath));
				//获得第一个工作表对象
				Sheet sheet = book.getSheet(3);				
				DataInfo dataInfo = null;
				//循环行Row，观测信息
			 	for (int rowNum = 1; rowNum <sheet.getRows(); rowNum++) {
			 		Cell[] cells = sheet.getRow(rowNum);
		            if (cells == null) {
		                continue;
		            }
		            dataInfo = new DataInfo();
		            //循环列Cell
		            Cell data_id = cells[0];
		            if (data_id == null) {
		                continue;
		            }		                
		            dataInfo.setDataId(Integer.parseInt(data_id.getContents()));
		            
		            Cell depth = cells[1];
		            if (depth == null) {
		                continue;
		            }		                
		            dataInfo.setDepth(depth.getContents());
		            
		            Cell lx = cells[2];
		            if (lx == null) {
		                continue;
		            }		                
		            dataInfo.setLx(lx.getContents());
		            
		            Cell ly = cells[3];
		            if (ly == null) {
		                continue;
		            }		                
		            dataInfo.setLy(ly.getContents());
		            
		            Cell error = cells[4];
		            if (error == null) {
		                continue;
		            }		                
		            dataInfo.setError(error.getContents());
		            
		            Cell theta_x = cells[5];
		            if (theta_x == null) {
		                continue;
		            }		                
		            dataInfo.setThetaX(theta_x.getContents());
		            
		            Cell theta_y = cells[6];
		            if (theta_y == null) {
		                continue;
		            }		                
		            dataInfo.setThetaY(theta_y.getContents());
		            
		            Cell theta = cells[7];
		            if (theta == null) {
		                continue;
		            }		                
		            dataInfo.setTheta(theta.getContents());
		            
		            Cell ob_id = cells[8];
		            if (ob_id == null) {
		                continue;
		            }		                
		            dataInfo.setObserverId(Integer.parseInt(ob_id.getContents()));

		            list.add(dataInfo);
			 	}
			 	
			 	book.close();
			 	
			} catch (BiffException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return list;
		}
		
		//观测信息
		public static List<ObserveInfo> loadObserveInfo(String xlsPath){
			List<ObserveInfo> list = new ArrayList<ObserveInfo>();
			try {
				Workbook book = Workbook.getWorkbook(new File(xlsPath));
				//获得第一个工作表对象
				Sheet sheet = book.getSheet(4);				
				ObserveInfo observeInfo = null;
				//循环行Row，观测信息
			 	for (int rowNum = 1; rowNum <sheet.getRows(); rowNum++) {
			 		Cell[] cells = sheet.getRow(rowNum);
		            if (cells == null) {
		                continue;
		            }
		            observeInfo = new ObserveInfo();
		            // 循环列Cell
		            Cell ob_id = cells[0];
		            if (ob_id == null) {
		                continue;
		            }
		            observeInfo.setObserveId(Integer.parseInt(ob_id.getContents()));
		            
		            Cell observer = cells[1];
		            if (observer == null) {
		                continue;
		            }
		            observeInfo.setObserver(observer.getContents());
		            
		            Cell time = cells[2];
		            if (time == null) {
		                continue;
		            }
		            observeInfo.setTime(time.getContents());
		            
		            Cell interval = cells[3];
		            if (interval == null) {
		                continue;
		            }
		            observeInfo.setInterval(interval.getContents());
		            
		            Cell measurecount = cells[4];
		            if (measurecount == null) {
		                continue;
		            }
		            observeInfo.setMeasurecount(measurecount.getContents());
		            
		            Cell slipdeep = cells[5];
		            if (slipdeep == null) {
		                continue;
		            }
		            observeInfo.setSlipdeep(slipdeep.getContents());
		            
		            Cell base_id = cells[6];
		            if (base_id == null) {
		                continue;
		            }
		            observeInfo.setBaseId(Integer.parseInt(base_id.getContents()));
		            
		            Cell count = cells[7];
		            if (count == null) {
		                continue;
		            }
		            observeInfo.setCount(Integer.parseInt(count.getContents()));
		            
		            list.add(observeInfo);   
			 	}
			 	
			 	book.close();
			 	
			} catch (BiffException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return list;
		}
		//钻孔基本信息
	    public static List<BaseInfo> loadBaseInfo(String xlsPath){	
		List<BaseInfo> list = new ArrayList<BaseInfo>();
		try {
			Workbook book = Workbook.getWorkbook(new File(xlsPath));
			//获得第一个工作表对象
			Sheet sheet = book.getSheet(5);				
			BaseInfo baseInfo = null;
			//循环行Row，钻孔信息
		 	for (int rowNum = 1; rowNum <sheet.getRows(); rowNum++) {
		 		Cell[] cells = sheet.getRow(rowNum);
	            if (cells == null) {
	                continue;
	            }
	            baseInfo = new BaseInfo();
	            // 循环列Cell
	            Cell base_id = cells[0];
	            if (base_id == null) {
	                continue;
	            }		                
	            baseInfo.setBaseId(Integer.parseInt(base_id.getContents()));
	            
	            Cell project_name = cells[1];
	            if (project_name == null) {
	                continue;
	            }
	            baseInfo.setProjectName(project_name.getContents());
	            
	            Cell item_name = cells[2];
	            if (item_name == null) {
	                continue;
	            }
	            baseInfo.setItemName(item_name.getContents());
	            
	            Cell drill_num = cells[3];
	            if (drill_num == null) {
	                continue;
	            }
	            baseInfo.setDrillNum(drill_num.getContents());
	            
	            Cell depth = cells[4];
	            if (depth == null) {
	                continue;
	            }
	            baseInfo.setDepth(depth.getContents());
	           
	            Cell mark1 = cells[5];
	            if (mark1 == null) {
	                continue;
	            }
	            baseInfo.setMark1(mark1.getContents());
	            
	            Cell mark2 = cells[6];
	            if (mark2 == null) {
	                continue;
	            }
	            baseInfo.setMark2(mark2.getContents());
	            
	            Cell mark3 = cells[7];
	            if (mark3 == null) {
	                continue;
	            }
	            baseInfo.setMark3(mark3.getContents());
	            
	            Cell mark4 = cells[8];
	            if (mark4 == null) {
	                continue;
	            }
	            baseInfo.setMark4(mark4.getContents());
	            
	            Cell loc = cells[9];
	            if (loc == null) {
	                continue;
	            }
	            baseInfo.setLoc(loc.getContents());
	            
	            Cell x = cells[10];
	            if (x == null) {
	                continue;
	            }
	            baseInfo.setX(x.getContents());
	            
	            Cell y = cells[11];
	            if (y == null) {
	                continue;
	            }
	            baseInfo.setY(y.getContents());
	            
	            Cell azimuth = cells[12];
	            if (azimuth == null) {
	                continue;
	            }
	            baseInfo.setAzimuth(azimuth.getContents());
	            
	            list.add(baseInfo);   
		 	}
		 	
		 	book.close();
		} catch (BiffException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}	
}
